import os

# 重命名(不改后缀)当前目录下的所有文件(不递归), 仅需实现handler


def renames(name_handler):
    """
    quick rename all the file in the current dir
    @param: name_handler: func(oldname:str) -> newname:str
    """
    _, script_name = os.path.split(__file__)
    for filename in os.listdir("./"):
        if filename == script_name:
            continue
        if os.path.isfile(filename):
            nm, ext = os.path.splitext(filename)
            new_name = name_handler(nm)
            print(new_name+ext)
            os.rename(filename, new_name+ext)


def handler(old_name):
    """
    @param: oldname不含后缀
    """
    return old_name+"1"


if __name__ == '__main__':
    s = input('Ready to rename?(y/n)')
    if s == 'y':
        # renames(lambda x: x+"1")
        # renames(handler)
        input('Press any to close...')
